﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GoogleMapLibrary;

public partial class WebUserControl : System.Web.UI.UserControl
{
    #region Properties
    GoogleMapObject _GoogleMap = new GoogleMapObject();
    public GoogleMapObject GoogleMap
    {
        get { return _GoogleMap; }
        set { _GoogleMap = value; }
    }

    Boolean _ShowControls = false;
    public Boolean ShowControls
    {
        get { return _ShowControls; }
        set { _ShowControls = value; }
    }

    #endregion


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["GOOGLE_MAP_OBJECT"] = GoogleMap;
        }
        else
        {
            GoogleMap = (GoogleMapObject)Session["GOOGLE_MAP_OBJECT"];
            if (GoogleMap == null)
            {
                GoogleMap = new GoogleMapObject();
                Session["GOOGLE_MAP_OBJECT"] = GoogleMap;
            }
        }

        if (GoogleMap != null)
        {
            GoogleMap.OnEventHandlerForGoogleMap(hidEventName.Value,hidEventValue.Value);
        }

        string sourceScript = "<script " +
                               "type=\"text/javascript\"" +
                               "src=\"http://maps.googleapis.com/maps/api/js?key=" + GoogleMap.APIKey + "&sensor=false\">" +
                           "</script>";
        sourceScript += "<script type='text/javascript' src='Scripts/GoogleMapAPIWrapper.js'></script>";
        sourceScript += "<script language='javascript'> if (window.DrawGoogleMap) { DrawGoogleMap(); } </script>";
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "onLoadCall", sourceScript);
    }
}